<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>医院内部成员登录页面</title>
  <link href="css/login.css" rel="stylesheet">
</head>

<body>
<div id="loginDiv" style="height: 350px">
  <form id="login">
    <h1 id="loginMsg">医院内部成员登录</h1>
    <div id="errorMsg"></div>
    <p>用户名:<input id="username" name="username" type="text"></p>
    <p>密码:<input id="password" name="password" type="password"></p>
    <div id="subDiv">
      <button class="button" type="submit">登录</button>&nbsp;&nbsp;&nbsp;
    </div>
  </form>
</div>

<script src="js/axios-0.18.0.js"></script>

<script>
  document.getElementById("login").addEventListener("submit",function (e){
    e.preventDefault();
    hospitalLogin();
  });
  function hospitalLogin(){
    var user = {};
    user.userName = document.getElementById("username").value;
    user.passWord = document.getElementById("password").value;
    axios({
      method:"post",
      url:"/user/hospitalLogin",
      data:user
    }).then(function (resp) {
      if(resp.data.code == 20052){
        localStorage.setItem("token",resp.data.data)
        window.location.assign("doctor.html");
      }else if(resp.data.code == 20053){
        localStorage.setItem("token",resp.data.data)
        window.location.assign("admin.html");
      }else if(resp.data.code == 20050){
        alert(resp.data.msg)
        window.location.assign("hospitalLogin.html");
      }else{
        alert(resp.data.msg)
        window.location.assign("hospitalLogin.html");
      }
    })
  }
</script>

</body>
</html>